package com.cambright.lotusroot
{
	import flash.utils.Dictionary;

	public dynamic class CommandMap extends Dictionary
	{
		static internal var $MODULE:Module;
		static internal var $HANDLER:Handler;
		
		static internal function $CLEAR():void
		{
			$MODULE = null;
			$HANDLER = null;
		}
		
		public function add(command:Class, handler:Class):void
		{
			this[command] = handler;
		}
		
		public function value(command:Class):Class
		{
			return this[command];
		}
		
		internal function $add(module:Module, command:Class, handler:Class):void
		{
			this[command] = [module, handler];
		}
		
		internal function $apply(command:Class):Boolean
		{
			var arr:Array = this[command];
			
			if(arr == null) return false;
			
			$MODULE = arr[0];
			$HANDLER = new arr[1];
			
			return true;
		}
	}
}